<?php
/**
 * Created by PhpStorm.
 * User: king
 * Date: 2016/9/28
 * Time: 14:36
 */

namespace App\Util;

class ResultsVo
{

    public $code = 0;

    public $message = '';

    public $data = [];

    public function __construct($data = [], $allow = [], $expect = [])
    {

        $this->code = isset($data['code']) ? intval($data['code']) : 0;
        $this->message = isset($data['message']) ? $data['message'] : '';

        if ($this->code) {
            unset($this->data);
        } else {
            if (isset($data['data'])) {
                if (isset($data['data']['results'])) {
                    $data['data']['results'] = Helper::arrayField($data['data']['results'], $allow, $expect);
                } else if (is_array($data['data'])) {
                    $data['data'] = Helper::arrayField($data['data'], $allow, $expect);
                }
                $this->data = $data['data'];
            } else {
                unset($this->data);
            }
        }

    }

}